package our.pack;

import java.util.List;

import android.content.Context;
import android.content.res.Resources;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.TextView;

public class TrackAdapter extends ArrayAdapter<Track> {

	private LayoutInflater inflater;
	
	public TrackAdapter(Context c, int textViewResourceId, List<Track> tracks) {
		super(c, textViewResourceId, tracks);
		inflater = LayoutInflater.from(c);
	}

	@Override
	public View getView(int p, View v, ViewGroup parent)
	{
		if( v == null )
		{
			v = inflater.inflate(R.layout.trackview, null);
		}
		
		Track t = getItem(p);
		if( t != null)
		{
			TextView trackNaam = (TextView)v.findViewById(R.id.tracknaamview);
			TextView trackDatum = (TextView)v.findViewById(R.id.trackdatumview);
			TextView trackAfstand = (TextView)v.findViewById(R.id.trackafstandview);
			TextView trackKM = (TextView)v.findViewById(R.id.trackkmview);
			
			trackNaam.setText(t.getTrackName());
			trackDatum.setText(t.getDateString());
			trackKM.setText(t.getDistance() + " KM");
			
		}
		return v;
	}
	
}
